package com.ruoyi.plus.api;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.api.ApiResult;
import com.ruoyi.common.core.api.BaseApi;
import com.ruoyi.common.core.api.version.ApiVersion;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * sysApi用于显示后端的接口名和版本号使用示例
 * @author likun
 */
@Slf4j
@Api(tags = "sysApi-系统Api")
@ApiVersion
@RestController
@RequestMapping(value = {"/app/api/plus/sysApi"})
public class SysApi extends BaseApi {

    @ApiOperation("getApiName-获取ApiName")
    @GetMapping("/getApiName")
    @ResponseBody
    public ApiResult<String> getApiName() {
        String apiName = RuoYiConfig.getApiName();
        if (StringUtils.isEmpty(apiName)) {
            return new ApiResult<String>().setData("");
        }
        return new ApiResult<String>(this.getApiVersion()).setData(apiName);
    }

    @ApiOperation("getApiName-获取ApiName_v2")
    @ApiVersion(ApiVersion.V2_0_0)
    @GetMapping("/getApiName")
    @ResponseBody
    public ApiResult<String> getApiName_v2() {
        String apiName = RuoYiConfig.getApiName();
        if (StringUtils.isEmpty(apiName)) {
            return new ApiResult<String>().setData("");
        }
        return new ApiResult<String>(ApiVersion.V2_0_0).setData(apiName);
    }

    @ApiOperation("getApiName-获取ApiName_v2_5_5")
    @ApiVersion("2.5.5")
    @GetMapping("/getApiName")
    @ResponseBody
    public ApiResult<String> getApiName_v2_5_5() {
        String apiName = RuoYiConfig.getApiName();
        if (StringUtils.isEmpty(apiName)) {
            return new ApiResult<String>().setData("");
        }
        return new ApiResult<String>("2.5.5").setData(apiName);
    }

}
